﻿CREATE PROCEDURE [dbo].[TempArticles_UpdateCategoryIds]
AS
	UPDATE TempArticles
	SET CategoryId = case when cat.Id is not null then cat.Id 
						else case when cm.Name is not null then cm.CategoryId
							else case when ar.NotFoundCategory = '000000' then 0
								else -1 end end end
	FROM TempArticles ar
	left join Categories cat on cat.Code = ar.NotFoundCategory
	left join CategoryMatch cm on cm.Name = ar.NotFoundCategory